package com.chen.recruit.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chen.recruit.common.api.CommonResult;
import com.chen.recruit.common.constants.MessageConstants;
import com.chen.recruit.common.enums.NoticeType;
import com.chen.recruit.service.NoticeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.chen.recruit.domain.Notice;
import com.chen.recruit.mapper.NoticeMapper;
import org.springframework.transaction.annotation.Transactional;

/**
 * 通知公告Service业务层处理
 *
 * @author cgy
 * @date 2022-08-17
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public CommonResult addOrUpdateNotice(Notice notice) {
        if (notice.getType() == NoticeType.TONG_ZHI && StringUtils.isNotBlank(notice.getContent())) {
            return CommonResult.fail(MessageConstants.TONG_ZHI_FAIL);
        }
        if (notice.getType() == NoticeType.GONG_GAO && StringUtils.isBlank(notice.getContent())) {
            return CommonResult.fail(MessageConstants.GONG_GAO_FAIL);
        }
        return this.saveOrUpdate(notice) ? CommonResult.success() : CommonResult.fail();
    }

}
